<template>
  <a-card :bordered="false">
      <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="企业名称">
              <j-input placeholder="请输入企业名称" v-model="queryParam.enterpriseName"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="审核状态">
              <j-dict-select-tag placeholder="请选择审核状态" v-model="queryParam.auditStatus" dictCode="audit_status"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus" :disabled="isDisabledAuth('erpOmcCustomer:add')">新增</a-button>
<!--      <a-button type="primary" icon="download" @click="handleExportXls('供应商')" :disabled="isDisabledAuth('erpPurchaseSupplier:export')">导出</a-button>-->
<!--      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">-->
<!--        <a-button type="primary" icon="import" :disabled="isDisabledAuth('erpPurchaseSupplier:import')">导入</a-button>-->
<!--      </a-upload>-->
      <!-- 高级查询区域 -->
      <!--<j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel" :disabled="isDisabledAuth('erpOmcCustomer:delete')"><a-icon type="delete"/>删除</a-menu-item>
          <a-menu-item key="2" @click="batchSubmit" :disabled="isDisabledAuth('erpOmcCustomer:submit')"><a-icon type="to-top" />提交</a-menu-item>
          <a-menu-item key="3" @click="batchAudit" :disabled="isDisabledAuth('erpOmcCustomer:audit')"><a-icon type="audit"/>审核</a-menu-item>
          <a-menu-item key="4" @click="batchCounterTrial" :disabled="isDisabledAuth('erpOmcCustomer:counterTrial')"><a-icon type="rollback" />反审</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item,index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12"><a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox></a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;"><a-icon type="setting" :style='iconStyle'/></a>
      </a-popover>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:scrollX}"
        :components="draggableComponent"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        :customRow="customRow"
        @change="handleTableChange">
        <template slot="status" slot-scope="status">
           <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">

        <template v-if="record.auditStatus==0">
            <a-button
                    class="ruleButton"
                    :ghost="true"
                    type="primary"
                    icon="edit"
                    @click="handleEdit(record)"
                    :disabled="isDisabledAuth('erpOmcCustomer:edit')"
            />
            <a-divider type="vertical" v-has="'erpOmcCustomer:delete'"/>
            <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)" v-has="'erpOmcCustomer:delete'">
                <a-button
                        class="ruleButton"
                        :ghost="true"
                        type="primary"
                        icon="delete"
                        :disabled="isDisabledAuth('erpOmcCustomer:delete')"/>
            </a-popconfirm>
            <a-divider type="vertical"/>
            <a-popconfirm title="确定提交吗?" @confirm="() => handleSubmit(record.id)" :hidden="isDisabledAuth('erpOmcCustomer:submit')">
                <a-button type="primary" size="small" v-has="'erpOmcCustomer:submit'"  :disabled="isDisabledAuth('erpOmcCustomer:submit')">提交</a-button>
            </a-popconfirm>

        </template>
        <template v-if="record.auditStatus==1" v-has="'erpOmcCustomer:audit'">
            <a-button type="primary" size="small" @click="handleAudit(record.id)"  :hidden="isDisabledAuth('erpOmcCustomer:audit')" :disabled="isDisabledAuth('erpOmcCustomer:audit')">审核</a-button>
        </template>
        <template v-if="record.auditStatus==2">
            <a-popconfirm title="确定反审吗?" @confirm="() => handleCounterTrial(record.id)" v-has="'erpOmcCustomer:counterTrial'">
                <a-button type="primary" size="small" style="margin-left: 10px"  :hidden="isDisabledAuth('erpPurchaseSupplier:counterTrial')" :disabled="isDisabledAuth('erpOmcCustomer:counterTrial')">反审</a-button>
            </a-popconfirm>
        </template>
        </span>

      </a-table>
    </div>

    <erp-omc-customer-manager-modal ref="modalForm" @ok="modalFormOk"></erp-omc-customer-manager-modal>
    <audit-modal ref="auditModal" @ok="modalFormOk"></audit-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ErpOmcCustomerManagerModal from './modules/ErpOmcCustomerManagerModal'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import {DisabledAuthFilterMixin} from '@/mixins/DisabledAuthFilterMixin'
  import { getAction, putAction } from '@api/manage';

  export default {
    name: 'ErpOmcCustomerManagerList',
    mixins:[JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
    components: {
      ErpOmcCustomerManagerModal,
    },
    data () {
      return {
        description: '供应商管理页面',
        //表头
        columns:[],
        //列设置
        settingColumns:[],
        //授信弹框
        syncModalVisible: false,
        //
        creditId: '',
        //遮罩
        syncLoading: false,
        // 列定义
        defColumns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'企业名称',
            align:"center",
            dataIndex: 'enterpriseName',
            width:300,
            ellipsis: true,
          },
          {
            title:'商户类型',
            align:"center",
            dataIndex: 'commercialType_dictText',
            width:124,
            ellipsis: true,
          },
          {
            title:'企业信用代码',
            align:"center",
            dataIndex: 'enterpriseCreditCode',
            width:172,
            ellipsis: true,
          },
          {
            title:'企业地址',
            align:"center",
            dataIndex: 'enterpriseAddress',
            width:172,
            ellipsis: true,
          },
          {
            title:'企业类型',
            align:"center",
            dataIndex: 'enterpriseType_dictText',
            width:124,
            ellipsis: true,
          },
          {
            title:'注册时间',
            align:"center",
            dataIndex: 'registerDate',
            width:160,
            ellipsis: true,
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'注册资本',
            align:"center",
            dataIndex: 'registerCapital',
            width:160,
            ellipsis: true,
          },
          {
            title:'审核状态',
            align:"center",
            dataIndex: 'auditStatus_dictText',
            scopedSlots: {customRender: 'status'},
            // fixed: "right",
            width:150,
            filterMultiple:false,
            filters: [
              {
                text: '待提交',
                value: 0,
              }, {
                text: '待审核',
                value: 1,
              }, {
                text: '已审核',
                value: 2,
              }],
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action' }
          }
        ],
        url: {
          list: '/api/erp/purchase/supplier/erpPurchaseSupplier/list?commercialType=1',
          delete: '/api/erp/purchase/supplier/erpPurchaseSupplier/delete',
          deleteBatch: '/api/erp/purchase/supplier/erpPurchaseSupplier/deleteBatch',
          exportXlsUrl: '/api/erp/purchase/supplier/erpPurchaseSupplier/exportXls',
          importExcelUrl: 'api/erp/purchase/supplier/erpPurchaseSupplier/importExcel',
          submit: '/api/erp/purchase/supplier/erpPurchaseSupplier/submit',
          submitBatch: '/api/erp/purchase/supplier/erpPurchaseSupplier/submitBatch',
          revoke: '/api/erp/purchase/supplier/erpPurchaseSupplier/revoke',
          revokeBatch: '/api/erp/purchase/supplier/erpPurchaseSupplier/revokeBatch',
          counterTrial: '/api/erp/purchase/supplier/erpPurchaseSupplier/counterTrial',
          counterTrialBatch: '/api/erp/purchase/supplier/erpPurchaseSupplier/counterTrialBatch',
          audit: '/api/erp/purchase/supplier/erpPurchaseSupplier/audit',
          auditBatch: '/api/erp/purchase/supplier/erpPurchaseSupplier/auditBatch',
          overrule: '/api/erp/purchase/supplier/erpPurchaseSupplier/overrule',
          overruleBatch: '/api/erp/purchase/supplier/erpPurchaseSupplier/overruleBatch',
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'enterpriseName',text:'企业名称',dictCode:''})
        fieldList.push({type:'string',value:'enterpriseCreditCode',text:'企业信用代码',dictCode:''})
        fieldList.push({type:'string',value:'enterpriseType',text:'企业类型',dictCode:'enterprise_type'})
        fieldList.push({type:'string',value:'legalRepresentative',text:'法定代表人',dictCode:''})
        fieldList.push({type:'string',value:'enterpriseAddress',text:'企业地址',dictCode:''})
        fieldList.push({type:'date',value:'registerDate',text:'公司注册时间'})
        fieldList.push({type:'string',value:'registerCapital',text:'注册资本',dictCode:''})
        fieldList.push({type:'string',value:'parentCategory',text:'供应大类',dictCode:''})
        fieldList.push({type:'string',value:'sonCategory',text:'供应小类',dictCode:''})
        fieldList.push({type:'string',value:'companyWeb',text:'公司网址',dictCode:''})
        fieldList.push({type:'string',value:'bankName',text:'开户行',dictCode:''})
        fieldList.push({type:'string',value:'bankCode',text:'开户卡号',dictCode:''})
        fieldList.push({type:'Text',value:'mainBussiness',text:'主营业务',dictCode:''})
        fieldList.push({type:'string',value:'legalRepresentativeCard',text:'法人身份证',dictCode:''})
        fieldList.push({type:'string',value:'bussinessLicense',text:'营业执照',dictCode:''})
        fieldList.push({type:'string',value:'supplierCertification',text:'供应商资质证书',dictCode:''})
        fieldList.push({type:'string',value:'cooperativeContract',text:'以往合作合同',dictCode:''})
        fieldList.push({type:'int',value:'auditStatus',text:'审核状态',dictCode:'audit_status'})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
